﻿@{
    ViewBag.Title = "validate";
}
@section header{
    <link media="screen" href="/ligerUI/skins/aqua/css/ligerui-all.css" type="text/css"
        rel="stylesheet" />
    <script type="text/javascript" src="/Scripts/jquery.form.js"></script>
    <script type="text/javascript" src="/Scripts/jquery.validate.min.js"></script>
    <script src="/Scripts/jquery.validate.message.cn.js" type="text/javascript"></script>

    <script type="text/javascript" src="/Scripts/base.js"></script>
    <script type="text/javascript" src="/Scripts/ligerTip.js"></script>
    <script type="text/javascript">
        $(function () {
            AjaxOnSubmit('comment_form', 'btnSubmit', '/feedback/ajax.ashx?action=add');
        });

        /*表单AJAX提交封装*/
        function AjaxOnSubmit(form_id, btn_id, send_url) {

            $('#' + form_id).validate({
                errorPlacement: function (lable, element) {
                    element.ligerTip({ content: lable.html(), appendIdTo: lable });
                },
                success: function (lable) {
                    lable.ligerHideTip();
                },
                submitHandler: function (form) {
                    //AJAX提交表单
                    $(form).ajaxSubmit({
                        beforeSubmit: formRequest,
                        success: formResponse,
                        error: formError,
                        url: send_url,           //处理ajax请求的地址
                        type: "post",
                        dataType: "json",
                        resetForm: true,
                        timeout: 30000
                    });
                    return false;
                }
            });

            //表单提交前
            function formRequest(formData, jqForm, options) {
                $("#" + btn_id).attr("disabled", "disabled");
                $("#" + btn_id).val("提交中...");
            }

            //表单提交后
            function formResponse(data, textStatus) {
                if (data.msg == 1) {
                    $("#" + btn_id).val("提交成功");
                    $("#" + btn_id).attr("disabled", "true");
                } else {
                    $("#" + btn_id).attr("disabled", "");
                    $("#" + btn_id).val("再次提交");
                }
            }

            //表单提交出错
            function formError(XMLHttpRequest, textStatus, errorThrown) {
                $("#" + btn_id).attr("disabled", "");
                $("#" + btn_id).val("再次提交");
            }
        }                  
    </script>

}
<form id="comment_form" name="comment_form">
<div class="index_feedback_add">
    <table>
        <tr>
            <td>
                <span class="red">*</span>留言内容:
            </td>
            <td>
                <textarea id="txtContent" name="txtContent" class="text required" rows="5" style="width: 120px;"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input name="btnSubmit" type="submit" value="发表留言" class="submit" id="btnSubmit">
            </td>
        </tr>
    </table>
</div>
</form>
